var oLayout = function(){
    this.sendding = false;
}
oLayout.prototype.initialize = function(){
    var self = this;

    $("#toggle-dropdown").click(function(e) {
                $(".menu-dropdown").slideToggle(100);
                $("#toggle-dropdown").toggleClass("ml-active");
            });
    $("#toggle-dropdown").mouseup(function() {
        return false
    });
    $(".menu-dropdown").mouseup(function() {
        return false
    });
    $('#main-menu li').bind('mouseover', self.openSubMenu);
    $('#main-menu li').bind('mouseout', self.closeSubMenu);
    
    jQuery(".tm-dropdown").hover(function()
    {
        jQuery(this).prev("#main-menu li a").toggleClass('focus');
    });
    $(document).mouseup(function(e) {
        if($(e.target).parent("div.menu-dropdown").length==0) {
            $("#toggle-dropdown").removeClass("ml-active");
            $(".menu-dropdown").slideUp(100);
        }
    });

    window.onload=function(){
        $('#main-menu li').each(function(){
            var id = $(this).attr('href');
            $(this).find('.tm-dropdown').html($('#'+id).html()).hide();
        })
        setHeaderMenu(CurrentModulCode,currentModulCodeForLeft);
        $('#main').css({
            'padding-top': $('#menu-full').height()
            // ,'height':$(window).height() - $('#footer').height() - hHeader
        });
        $('.tm-dropdown .content').css('padding-left',$('#main-menu li:first').position().left);
        // $('#footer').css({'position': 'absolute'});
    }       
    $('p.file_export_close').click(function(){
        $('div#note-process').removeClass('vY nq');
        $('div#note-process').hide();
        $('div#file_export').hide(); 
    });
    // $('#menu').disableSelection();
}
/**
Create: Truongdv
Des: NSD Click vao Menu Head Load Ajax
*/
oLayout.prototype.redirect = function(obj,curentModule,currentModulCodeForLeft){
    var url = $(obj).attr('href')
        ,self = this;
    var data = {
        url:url,
        module:curentModule
    };
    if (history.pushState) history.pushState("", "", url);
    if (typeof($("div#main").load) ==='undefined') {
        window.location.href = url;
        location.reload(); 
    }else{
        self.showLoadPage();
        $("div#main").load(url,data,function(string){
            removeEventOld();
            setHeaderMenu(curentModule,currentModulCodeForLeft);
            self.hideLoadPage();
        });
    }
    return !history.pushState;
}

$.extend(oLayout.prototype,{
    showLoadPage: function(){
        if(this.sendding) return false;
        this.sendding = true;
        var clientHeight = document.documentElement.clientHeight;
        clientHeight = clientHeight*1/5 ;
        //Loading
        $('div#note-process').addClass('nq vY');   
        $('div#note-process').show();
        // $('div#loadingpage').css('top',clientHeight+'px');
        // $('div#loadingpage').show();
    },
    hideLoadPage: function(){
        $('div#note-process').removeClass('vY nq');
        $('div#note-process').hide();
        this.sendding = false;
        // $('div#loadingpage').hide();
    },
    openSubMenu: function(){
        var id = $(this).attr('href');
        $(this).find('.tm-dropdown').css({'visibility':'visible','width':'auto'});
    },
    closeSubMenu: function(){

        $(this).find('.tm-dropdown').css('visibility', 'hidden');
    },
    _CONST:{
        localizationobj: {
              pagergotopagestring:"Tới trang:"
              ,pagershowrowsstring: "Số hồ sơ trên trang:"
              ,pagerrangestring: " đến "
              ,pagernextbuttonstring: "Tiếp theo"
              ,pagerpreviousbuttonstring: "Trước"
              ,filterchoosestring:"Vui lòng chọn"
              ,sortascendingstring: "Tăng dần"
              ,sortdescendingstring: "Giảm dần"
              ,sortremovestring: "Bỏ sắp xếp"
        }
    },
    getNameByCode: function(data,Code){
        var iMax = data.length
            ,Name ='';
        for (var i = 0; i < iMax; i++) {
            if (data[i]['Code'] == Code) {
                Name = data[i]['Name'];
                break;
            };
        };
        return Name;
    },
})

oLayout.prototype.loadfileJsCss = function(data){
    var count = data.length;
    for (var i = 0; i < count; i++){
        if(data[i][1] ==='js'){
            if($('script[src="'+data[i][0]+'"]').length == 0)
                $('head').append('<script src="' + data[i][0] + '" type="text/javascript" charset="utf-8"></script>');
        }else{
            if($('link[href="'+data[i][0]+'"]').length == 0)
                $('head').append('<link rel="stylesheet" type="text/css" href="' + data[i]['0'] + '">');
        }
    };
}